package com.xiaoxiong.mami.dao.mapperImpl;

import com.xiaoxiong.mami.dao.daomain.OrderInfo;
import com.xiaoxiong.mami.dao.mapper.OrderInfoMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderInfoMapperImpl extends OrderInfoMapper {



    @Select("select * from order_info where orderId =#{orderId} ")
    List<OrderInfo> queryOrderByOrderId(String orderId);

    @Select("select * from order_info where orderId =#{orderId} and userId=#{userId} limit 1")
    OrderInfo queryOrderItem(@Param("userId") String userId,@Param("orderId") String orderId);


    @Select("select * from order_info where orderId =#{orderId} limit 1")
    OrderInfo queryOrderItemById(@Param("orderId") String orderId);


    @Select("select * from order_info where userId =#{userId} and orderStatus = #{orderStatus} order by updateTime desc  limit #{start},#{end} ")
    List<OrderInfo> getOrderListByUserIdAndStatus(@Param("userId")String userId,@Param("orderStatus") String orderStatus,@Param("start")int start,@Param("end")int end);

    @Select("select * from order_info where userId =#{userId} order by updateTime desc  limit #{start},#{end} ")
    List<OrderInfo> getOrderListByUserId(@Param("userId")String userId,@Param("start")int start,@Param("end")int end);

    @Select("select * from order_info where orderStatus = #{orderStatus} order by updateTime asc  ")
    List<OrderInfo> getOrderListByStatus(@Param("orderStatus") String orderStatus);


    @Select("select * from order_info where orderStatus = #{orderStatus} order by updateTime asc  limit #{start},#{end}")
    List<OrderInfo> getOrderListByStatusLimit(@Param("orderStatus") String orderStatus,@Param("start")int start,@Param("end")int end);


    @Select("select count(*) from order_info where userid =#{userId} and orderStatus=#{orderStatus}")
    int getOrderCountByStatus(@Param("userId")String userId,@Param("orderStatus") String orderStatus);

    @Select("select count(*) from order_info where orderStatus=#{orderStatus}")
    int getOrderCountStatus(@Param("orderStatus") String orderStatus);

    @Select("select count(*) from order_info where userid =#{userId}")
    int getOrderCount(@Param("userId")String userId);

    @Select("select count(*) from order_info where orderId =#{orderId} ")
    int queryCountByOrderId(String orderId);

    @Insert({
            "insert into order_info (userId,orderId,",
            "orderType, orderTitle, ",
            "orderDescribe, ",
            "orderAddress, payType, ",
            "orderStatus, updateTime, ",
            "createTime, goodsId, orderIdentifier,",
            "totalMoney,receiver,telephone,statusName)",
            "values (#{userId}, #{orderId,jdbcType=VARCHAR}, ",
            "#{orderType,jdbcType=VARCHAR}, #{orderTitle,jdbcType=VARCHAR}, ",
            "#{orderDescribe,jdbcType=VARCHAR}, ",
            "#{orderAddress,jdbcType=VARCHAR}, #{payType,jdbcType=VARCHAR}, ",
            "#{orderStatus,jdbcType=VARCHAR}, now(), ",
            "now(),#{goodsId},#{orderIdentifier}, ",
            "#{totalMoney,jdbcType=VARCHAR},#{receiver},#{telephone},#{statusName})"
    })
    int insertOrder(OrderInfo orderInfo);


    @Select("select * from order_info where orderId = #{orderId} limit 1")
    OrderInfo getOrderByOrderId(String orderId);

    @Update({
            "update order_info set orderStatus = #{orderStatus},statusName = #{statusName}, updateTime = now() where orderId = #{orderId}"
    })
    int updateStatusByOrderId(@Param("orderId") String orderId,
                              @Param("orderStatus") String orderStatus,@Param("statusName") String statusName);
}